-- ------------------------------
-- table 得到删除所有表的sql
-- sequence 得到删除所有sequence的sql
-- view 得到删除所有view的sql
-- FUNCTION 得到删除所有FUNCTION的sql
-- ------------------------------
select 'drop table '||tabschema||'.'||tabname||';'from syscat.tables where tabschema ='DEMO';
select 'drop sequence '||seqschema||'.'||seqname||';'from syscat.sequences where seqschema ='DEMO';
select 'drop view '||viewschema||'.'||viewname||';'from syscat.views where viewschema ='DEMO';
select 'DROP FUNCTION  '||funcschema||'.'||funcname||';'from syscat.FUNCPARMS where funcschema ='DEMO';

-- ----------------------------
-- 1、部门表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_DEPT
 INCREMENT BY 1
 START WITH 200
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_DEPT (
  DEPT_ID           BIGINT      NOT NULL,
  PARENT_ID         BIGINT      DEFAULT 0,
  ANCESTORS         VARCHAR(50)    DEFAULT '',
  DEPT_NAME         VARCHAR(30)    DEFAULT '',
  ORDER_NUM         INTEGER       DEFAULT 0,
  LEADER            VARCHAR(20)    DEFAULT NULL,
  PHONE             VARCHAR(11)    DEFAULT NULL,
  EMAIL             VARCHAR(50)    DEFAULT NULL,
  STATUS            CHARACTER(1)         DEFAULT '0',
  DEL_FLAG          CHARACTER(1)         DEFAULT '0',
  CREATE_BY         VARCHAR(64)    DEFAULT '',
  CREATE_TIME 	    TIMESTAMP,
  UPDATE_BY         VARCHAR(64)    DEFAULT '',
  UPDATE_TIME       TIMESTAMP
);

ALTER TABLE SYS_DEPT ADD CONSTRAINT PK_SYS_DEPT PRIMARY KEY (DEPT_ID);

COMMENT ON TABLE  SYS_DEPT              IS '部门信息表';
COMMENT ON COLUMN SYS_DEPT.DEPT_ID      IS '部门主键SEQ_SYS_DEPT.NEXTVAL';
COMMENT ON COLUMN SYS_DEPT.PARENT_ID    IS '父部门ID';
COMMENT ON COLUMN SYS_DEPT.ANCESTORS    IS '祖级列表';
COMMENT ON COLUMN SYS_DEPT.DEPT_NAME    IS '部门名称';
COMMENT ON COLUMN SYS_DEPT.ORDER_NUM    IS '显示顺序';
COMMENT ON COLUMN SYS_DEPT.LEADER       IS '负责人';
COMMENT ON COLUMN SYS_DEPT.PHONE        IS '联系电话';
COMMENT ON COLUMN SYS_DEPT.EMAIL        IS '邮箱';
COMMENT ON COLUMN SYS_DEPT.STATUS       IS '部门状态（0正常 1停用）';
COMMENT ON COLUMN SYS_DEPT.DEL_FLAG     IS '删除标志（0代表存在 2代表删除）';
COMMENT ON COLUMN SYS_DEPT.CREATE_BY    IS '创建者';
COMMENT ON COLUMN SYS_DEPT.CREATE_TIME  IS '创建时间';
COMMENT ON COLUMN SYS_DEPT.UPDATE_BY    IS '更新者';
COMMENT ON COLUMN SYS_DEPT.UPDATE_TIME  IS '更新时间';

-- ----------------------------
-- 初始化-部门表数据
-- ----------------------------
INSERT INTO SYS_DEPT VALUES(100,  0,   '0',          '若依科技',   0, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(101,  100, '0,100',      '深圳总公司', 1, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(102,  100, '0,100',      '长沙分公司', 2, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(103,  101, '0,100,101',  '研发部门',   1, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(104,  101, '0,100,101',  '市场部门',   2, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(105,  101, '0,100,101',  '测试部门',   3, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(106,  101, '0,100,101',  '财务部门',   4, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(107,  101, '0,100,101',  '运维部门',   5, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(108,  102, '0,100,102',  '市场部门',   1, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);
INSERT INTO SYS_DEPT VALUES(109,  102, '0,100,102',  '财务部门',   2, '若依', '15888888888', 'ry@qq.com', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL);

-- ----------------------------
-- 2、用户信息表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_USER
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_USER (
  USER_ID           BIGINT      NOT NULL,
  DEPT_ID           BIGINT      DEFAULT NULL,
  LOGIN_NAME        VARCHAR(30)    NOT NULL,
  USER_NAME         VARCHAR(30)    DEFAULT '',
  USER_TYPE         VARCHAR(2)     DEFAULT '00',
  EMAIL             VARCHAR(50)    DEFAULT '',
  PHONENUMBER       VARCHAR(11)    DEFAULT '',
  SEX               CHARACTER(1)         DEFAULT '0',
  AVATAR            VARCHAR(100)   DEFAULT '',
  PASSWORD          VARCHAR(50)    DEFAULT '',
  SALT              VARCHAR(20)    DEFAULT '',
  STATUS            CHARACTER(1)         DEFAULT '0',
  DEL_FLAG          CHARACTER(1)         DEFAULT '0',
  LOGIN_IP          VARCHAR(128)   DEFAULT '',
  LOGIN_DATE        TIMESTAMP,
  PWD_UPDATE_DATE   TIMESTAMP,
  CREATE_BY         VARCHAR(64),
  CREATE_TIME 	    TIMESTAMP,
  UPDATE_BY         VARCHAR(64)    DEFAULT '',
  UPDATE_TIME       TIMESTAMP,
  REMARK            VARCHAR(500)   DEFAULT ''
);

ALTER TABLE SYS_USER ADD CONSTRAINT PK_SYS_USER PRIMARY KEY (USER_ID);

COMMENT ON TABLE  SYS_USER                  IS '用户信息表';
COMMENT ON COLUMN SYS_USER.USER_ID          IS '用户主键SEQ_SYS_USER.NEXTVAL';
COMMENT ON COLUMN SYS_USER.DEPT_ID          IS '部门ID';
COMMENT ON COLUMN SYS_USER.LOGIN_NAME       IS '登录账号';
COMMENT ON COLUMN SYS_USER.USER_NAME        IS '用户昵称';
COMMENT ON COLUMN SYS_USER.USER_TYPE        IS '用户类型（00系统用户 01注册用户）';
COMMENT ON COLUMN SYS_USER.EMAIL            IS '用户邮箱';
COMMENT ON COLUMN SYS_USER.PHONENUMBER      IS '手机号码';
COMMENT ON COLUMN SYS_USER.SEX              IS '用户性别（0男 1女 2未知）';
COMMENT ON COLUMN SYS_USER.AVATAR           IS '头像路径';
COMMENT ON COLUMN SYS_USER.PASSWORD         IS '密码';
COMMENT ON COLUMN SYS_USER.SALT             IS '盐加密';
COMMENT ON COLUMN SYS_USER.STATUS           IS '帐号状态（0正常 1停用）';
COMMENT ON COLUMN SYS_USER.DEL_FLAG         IS '删除标志（0代表存在 2代表删除）';
COMMENT ON COLUMN SYS_USER.LOGIN_IP         IS '最后登录IP';
COMMENT ON COLUMN SYS_USER.LOGIN_DATE       IS '最后登录时间';
COMMENT ON COLUMN SYS_USER.PWD_UPDATE_DATE  IS '密码最后更新时间';
COMMENT ON COLUMN SYS_USER.CREATE_BY        IS '创建者';
COMMENT ON COLUMN SYS_USER.CREATE_TIME      IS '创建时间';
COMMENT ON COLUMN SYS_USER.UPDATE_BY        IS '更新者';
COMMENT ON COLUMN SYS_USER.UPDATE_TIME      IS '更新时间';
COMMENT ON COLUMN SYS_USER.REMARK           IS '备注';

-- ----------------------------
-- 初始化-用户信息表数据
-- ----------------------------
INSERT INTO SYS_USER VALUES(1,  103, 'admin', '若依', '00', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', '0', '0', '127.0.0.1', CURRENT TIMESTAMP, CURRENT TIMESTAMP, 'admin', CURRENT TIMESTAMP, '', NULL, '管理员');
INSERT INTO SYS_USER VALUES(2,  105, 'ry',    '若依', '00', 'ry@qq.com',  '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', '0', '0', '127.0.0.1', CURRENT TIMESTAMP, CURRENT TIMESTAMP, 'admin', CURRENT TIMESTAMP, '', NULL, '测试员');


-- ----------------------------
-- 3、岗位信息表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_POST
 INCREMENT BY 1
 START WITH 10
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_POST
(
  POST_ID           BIGINT      NOT NULL,
  POST_CODE         VARCHAR(64)    NOT NULL,
  POST_NAME         VARCHAR(50)    NOT NULL,
  POST_SORT         INTEGER       NOT NULL,
  STATUS            CHARACTER(1)         NOT NULL,
  CREATE_BY         VARCHAR(64)    DEFAULT '',
  CREATE_TIME       TIMESTAMP,
  UPDATE_BY         VARCHAR(64)    DEFAULT '',
  UPDATE_TIME       TIMESTAMP,
  REMARK            VARCHAR(500)
);

ALTER TABLE SYS_POST ADD CONSTRAINT PK_SYS_POST PRIMARY KEY (POST_ID);

COMMENT ON TABLE  SYS_POST              IS '岗位信息表';
COMMENT ON COLUMN SYS_POST.POST_ID      IS '岗位主键SEQ_SYS_POST.NEXTVAL';
COMMENT ON COLUMN SYS_POST.POST_CODE    IS '岗位编码';
COMMENT ON COLUMN SYS_POST.POST_NAME    IS '岗位名称';
COMMENT ON COLUMN SYS_POST.POST_SORT    IS '显示顺序';
COMMENT ON COLUMN SYS_POST.STATUS       IS '状态（0正常 1停用）';
COMMENT ON COLUMN SYS_POST.CREATE_BY    IS '创建者';
COMMENT ON COLUMN SYS_POST.CREATE_TIME  IS '创建时间';
COMMENT ON COLUMN SYS_POST.UPDATE_BY    IS '更新者';
COMMENT ON COLUMN SYS_POST.UPDATE_TIME  IS '更新时间';
COMMENT ON COLUMN SYS_POST.REMARK       IS '备注';

-- ----------------------------
-- 初始化-岗位信息表数据
-- ----------------------------
INSERT INTO SYS_POST VALUES(1,'ceo',  '董事长',     1, '0', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_POST VALUES(2,'se',   '项目经理',   2, '0', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_POST VALUES(3,'hr',   '人力资源',   3, '0', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_POST VALUES(4,'user', '普通员工',   4, '0', 'admin', CURRENT TIMESTAMP, '', NULL, '');

-- ----------------------------
-- 4、角色信息表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_ROLE
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_ROLE (
  ROLE_ID           BIGINT      NOT NULL,
  ROLE_NAME         VARCHAR(30)    NOT NULL,
  ROLE_KEY          VARCHAR(100)   NOT NULL,
  ROLE_SORT         INTEGER       NOT NULL,
  DATA_SCOPE        CHARACTER(1)         DEFAULT '1',
  STATUS            CHARACTER(1)         NOT NULL,
  DEL_FLAG          CHARACTER(1)         DEFAULT '0',
  CREATE_BY         VARCHAR(64)    DEFAULT '',
  CREATE_TIME       TIMESTAMP,
  UPDATE_BY         VARCHAR(64)    DEFAULT '',
  UPDATE_TIME       TIMESTAMP,
  REMARK            VARCHAR(500)   DEFAULT NULL
);

ALTER TABLE SYS_ROLE ADD CONSTRAINT PK_SYS_ROLE PRIMARY KEY (ROLE_ID);

COMMENT ON TABLE  SYS_ROLE              IS '角色信息表';
COMMENT ON COLUMN SYS_ROLE.ROLE_ID      IS '角色主键SEQ_SYS_POST.NEXTVAL';
COMMENT ON COLUMN SYS_ROLE.ROLE_NAME    IS '角色名称';
COMMENT ON COLUMN SYS_ROLE.ROLE_KEY     IS '角色权限字符串';
COMMENT ON COLUMN SYS_ROLE.ROLE_SORT    IS '显示顺序';
COMMENT ON COLUMN SYS_ROLE.DATA_SCOPE   IS '数据范围（1：全部数据权限 2：自定数据权限）';
COMMENT ON COLUMN SYS_ROLE.STATUS       IS '角色状态（0正常 1停用）';
COMMENT ON COLUMN SYS_ROLE.DEL_FLAG     IS '删除标志（0代表存在 2代表删除）';
COMMENT ON COLUMN SYS_ROLE.CREATE_BY    IS '创建者';
COMMENT ON COLUMN SYS_ROLE.CREATE_TIME  IS '创建时间';
COMMENT ON COLUMN SYS_ROLE.UPDATE_BY    IS '更新者';
COMMENT ON COLUMN SYS_ROLE.UPDATE_TIME  IS '更新时间';
COMMENT ON COLUMN SYS_ROLE.REMARK       IS '备注';

-- ----------------------------
-- 初始化-角色信息表数据
-- ----------------------------
INSERT INTO SYS_ROLE VALUES(1, '超级管理员',  'admin',  1, '1', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '超级管理员');
INSERT INTO SYS_ROLE VALUES(2, '普通角色',    'common', 2, '2', '0', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '普通角色');


-- ----------------------------
-- 5、菜单权限表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_MENU
 INCREMENT BY 1
 START WITH 2000
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_MENU (
  MENU_ID           BIGINT      NOT NULL,
  MENU_NAME         VARCHAR(50)    NOT NULL,
  PARENT_ID         BIGINT      DEFAULT 0,
  ORDER_NUM         INTEGER       DEFAULT 0,
  URL               VARCHAR(200)   DEFAULT '#',
  TARGET            VARCHAR(20)    DEFAULT '',
  MENU_TYPE         CHARACTER(1)         DEFAULT '',
  VISIBLE           CHARACTER(1)         DEFAULT '0',
  IS_REFRESH        CHARACTER(1)         DEFAULT '1',
  PERMS             VARCHAR(100)   DEFAULT NULL,
  ICON              VARCHAR(100)   DEFAULT '#',
  CREATE_BY         VARCHAR(64)    DEFAULT '',
  CREATE_TIME       TIMESTAMP,
  UPDATE_BY         VARCHAR(64)    DEFAULT '',
  UPDATE_TIME       TIMESTAMP ,
  REMARK            VARCHAR(500)   DEFAULT ''
);

ALTER TABLE SYS_MENU ADD CONSTRAINT PK_SYS_MENU PRIMARY KEY (MENU_ID);

COMMENT ON TABLE  SYS_MENU              IS '菜单权限表';
COMMENT ON COLUMN SYS_MENU.MENU_ID      IS '菜单主键SEQ_SYS_POST.NEXTVAL';
COMMENT ON COLUMN SYS_MENU.MENU_NAME    IS '菜单名称';
COMMENT ON COLUMN SYS_MENU.PARENT_ID    IS '父菜单ID';
COMMENT ON COLUMN SYS_MENU.ORDER_NUM    IS '显示顺序';
COMMENT ON COLUMN SYS_MENU.URL          IS '请求地址';
COMMENT ON COLUMN SYS_MENU.TARGET       IS '打开方式（menuitem页签 menublank新窗口）';
COMMENT ON COLUMN SYS_MENU.MENU_TYPE    IS '菜单类型（M目录 C菜单 F按钮）';
COMMENT ON COLUMN SYS_MENU.VISIBLE      IS '菜单状态（0显示 1隐藏）';
COMMENT ON COLUMN SYS_MENU.IS_REFRESH   IS '是否刷新（0刷新 1不刷新）';
COMMENT ON COLUMN SYS_MENU.PERMS        IS '权限标识';
COMMENT ON COLUMN SYS_MENU.ICON         IS '菜单图标';
COMMENT ON COLUMN SYS_MENU.CREATE_BY    IS '创建者';
COMMENT ON COLUMN SYS_MENU.CREATE_TIME  IS '创建时间';
COMMENT ON COLUMN SYS_MENU.UPDATE_BY    IS '更新者';
COMMENT ON COLUMN SYS_MENU.UPDATE_TIME  IS '更新时间';
COMMENT ON COLUMN SYS_MENU.REMARK       IS '备注';

-- ----------------------------
-- 初始化-菜单信息表数据
-- ----------------------------
-- 一级菜单
INSERT INTO SYS_MENU VALUES(1, '系统管理', 0, 1, '#',                '',          'M', '0', '1', '', 'fa fa-gear',           'admin', CURRENT TIMESTAMP, '', NULL, '系统管理目录');
INSERT INTO SYS_MENU VALUES(2, '系统监控', 0, 2, '#',                '',          'M', '0', '1', '', 'fa fa-video-camera',   'admin', CURRENT TIMESTAMP, '', NULL, '系统监控目录');
INSERT INTO SYS_MENU VALUES(3, '系统工具', 0, 3, '#',                '',          'M', '0', '1', '', 'fa fa-bars',           'admin', CURRENT TIMESTAMP, '', NULL, '系统工具目录');
INSERT INTO SYS_MENU VALUES(4, '若依官网', 0, 4, 'http://ruoyi.vip', 'menublank', 'C', '0', '1', '', 'fa fa-location-arrow', 'admin', CURRENT TIMESTAMP, '', NULL, '若依官网地址');
-- 二级菜单
INSERT INTO SYS_MENU VALUES(100,  '用户管理', 1, 1, '/system/user',          '', 'C', '0', '1', 'system:user:view',         'fa fa-user-o',          'admin', CURRENT TIMESTAMP, '', NULL, '用户管理菜单');
INSERT INTO SYS_MENU VALUES(101,  '角色管理', 1, 2, '/system/role',          '', 'C', '0', '1', 'system:role:view',         'fa fa-user-secret',     'admin', CURRENT TIMESTAMP, '', NULL, '角色管理菜单');
INSERT INTO SYS_MENU VALUES(102,  '菜单管理', 1, 3, '/system/menu',          '', 'C', '0', '1', 'system:menu:view',         'fa fa-th-list',         'admin', CURRENT TIMESTAMP, '', NULL, '菜单管理菜单');
INSERT INTO SYS_MENU VALUES(103,  '部门管理', 1, 4, '/system/dept',          '', 'C', '0', '1', 'system:dept:view',         'fa fa-outdent',         'admin', CURRENT TIMESTAMP, '', NULL, '部门管理菜单');
INSERT INTO SYS_MENU VALUES(104,  '岗位管理', 1, 5, '/system/post',          '', 'C', '0', '1', 'system:post:view',         'fa fa-address-card-o',  'admin', CURRENT TIMESTAMP, '', NULL, '岗位管理菜单');
INSERT INTO SYS_MENU VALUES(105,  '字典管理', 1, 6, '/system/dict',          '', 'C', '0', '1', 'system:dict:view',         'fa fa-bookmark-o',      'admin', CURRENT TIMESTAMP, '', NULL, '字典管理菜单');
INSERT INTO SYS_MENU VALUES(106,  '参数设置', 1, 7, '/system/config',        '', 'C', '0', '1', 'system:config:view',       'fa fa-sun-o',           'admin', CURRENT TIMESTAMP, '', NULL, '参数设置菜单');
INSERT INTO SYS_MENU VALUES(107,  '通知公告', 1, 8, '/system/notice',        '', 'C', '0', '1', 'system:notice:view',       'fa fa-bullhorn',        'admin', CURRENT TIMESTAMP, '', NULL, '通知公告菜单');
INSERT INTO SYS_MENU VALUES(108,  '日志管理', 1, 9, '#',                     '', 'M', '0', '1', '',                         'fa fa-pencil-square-o', 'admin', CURRENT TIMESTAMP, '', NULL, '日志管理菜单');
INSERT INTO SYS_MENU VALUES(109,  '在线用户', 2, 1, '/monitor/online',       '', 'C', '0', '1', 'monitor:online:view',      'fa fa-user-circle',     'admin', CURRENT TIMESTAMP, '', NULL, '在线用户菜单');
INSERT INTO SYS_MENU VALUES(110,  '定时任务', 2, 2, '/monitor/job',          '', 'C', '0', '1', 'monitor:job:view',         'fa fa-tasks',           'admin', CURRENT TIMESTAMP, '', NULL, '定时任务菜单');
INSERT INTO SYS_MENU VALUES(111,  '数据监控', 2, 3, '/monitor/data',         '', 'C', '0', '1', 'monitor:data:view',        'fa fa-bug',             'admin', CURRENT TIMESTAMP, '', NULL, '数据监控菜单');
INSERT INTO SYS_MENU VALUES(112,  '服务监控', 2, 4, '/monitor/server',       '', 'C', '0', '1', 'monitor:server:view',      'fa fa-server',          'admin', CURRENT TIMESTAMP, '', NULL, '服务监控菜单');
INSERT INTO SYS_MENU VALUES(113,  '缓存监控', 2, 5, '/monitor/cache',        '', 'C', '0', '1', 'monitor:cache:view',       'fa fa-cube',            'admin', CURRENT TIMESTAMP, '', NULL, '缓存监控菜单');
INSERT INTO SYS_MENU VALUES(114,  '表单构建', 3, 1, '/tool/build',           '', 'C', '0', '1', 'tool:build:view',          'fa fa-wpforms',         'admin', CURRENT TIMESTAMP, '', NULL, '表单构建菜单');
INSERT INTO SYS_MENU VALUES(115,  '代码生成', 3, 2, '/tool/gen',             '', 'C', '0', '1', 'tool:gen:view',            'fa fa-code',            'admin', CURRENT TIMESTAMP, '', NULL, '代码生成菜单');
INSERT INTO SYS_MENU VALUES(116,  '系统接口', 3, 3, '/tool/swagger',         '', 'C', '0', '1', 'tool:swagger:view',        'fa fa-gg',              'admin', CURRENT TIMESTAMP, '', NULL, '系统接口菜单');
-- 三级菜单
INSERT INTO SYS_MENU VALUES(500,  '操作日志', 108, 1, '/monitor/operlog',    '', 'C', '0', '1', 'monitor:operlog:view',     'fa fa-address-book',    'admin', CURRENT TIMESTAMP, '', NULL, '操作日志菜单');
INSERT INTO SYS_MENU VALUES(501,  '登录日志', 108, 2, '/monitor/logininfor', '', 'C', '0', '1', 'monitor:logininfor:view',  'fa fa-file-image-o',    'admin', CURRENT TIMESTAMP, '', NULL, '登录日志菜单');
-- 用户管理按钮
INSERT INTO SYS_MENU VALUES(1000, '用户查询', 100, 1,  '#', '',  'F', '0', '1', 'system:user:list',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1001, '用户新增', 100, 2,  '#', '',  'F', '0', '1', 'system:user:add',         '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1002, '用户修改', 100, 3,  '#', '',  'F', '0', '1', 'system:user:edit',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1003, '用户删除', 100, 4,  '#', '',  'F', '0', '1', 'system:user:remove',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1004, '用户导出', 100, 5,  '#', '',  'F', '0', '1', 'system:user:export',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1005, '用户导入', 100, 6,  '#', '',  'F', '0', '1', 'system:user:import',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1006, '重置密码', 100, 7,  '#', '',  'F', '0', '1', 'system:user:resetpwd',    '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 角色管理按钮
INSERT INTO SYS_MENU VALUES(1007, '角色查询', 101, 1,  '#', '',  'F', '0', '1', 'system:role:list',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1008, '角色新增', 101, 2,  '#', '',  'F', '0', '1', 'system:role:add',         '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1009, '角色修改', 101, 3,  '#', '',  'F', '0', '1', 'system:role:edit',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1010, '角色删除', 101, 4,  '#', '',  'F', '0', '1', 'system:role:remove',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1011, '角色导出', 101, 5,  '#', '',  'F', '0', '1', 'system:role:export',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 菜单管理按钮
INSERT INTO SYS_MENU VALUES(1012, '菜单查询', 102, 1,  '#', '',  'F', '0', '1', 'system:menu:list',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1013, '菜单新增', 102, 2,  '#', '',  'F', '0', '1', 'system:menu:add',         '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1014, '菜单修改', 102, 3,  '#', '',  'F', '0', '1', 'system:menu:edit',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1015, '菜单删除', 102, 4,  '#', '',  'F', '0', '1', 'system:menu:remove',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 部门管理按钮
INSERT INTO SYS_MENU VALUES(1016, '部门查询', 103, 1,  '#', '',  'F', '0', '1', 'system:dept:list',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1017, '部门新增', 103, 2,  '#', '',  'F', '0', '1', 'system:dept:add',         '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1018, '部门修改', 103, 3,  '#', '',  'F', '0', '1', 'system:dept:edit',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1019, '部门删除', 103, 4,  '#', '',  'F', '0', '1', 'system:dept:remove',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 岗位管理按钮
INSERT INTO SYS_MENU VALUES(1020, '岗位查询', 104, 1,  '#', '',  'F', '0', '1', 'system:post:list',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1021, '岗位新增', 104, 2,  '#', '',  'F', '0', '1', 'system:post:add',         '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1022, '岗位修改', 104, 3,  '#', '',  'F', '0', '1', 'system:post:edit',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1023, '岗位删除', 104, 4,  '#', '',  'F', '0', '1', 'system:post:remove',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1024, '岗位导出', 104, 5,  '#', '',  'F', '0', '1', 'system:post:export',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 字典管理按钮
INSERT INTO SYS_MENU VALUES(1025, '字典查询', 105, 1,  '#', '',  'F', '0', '1', 'system:dict:list',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1026, '字典新增', 105, 2,  '#', '',  'F', '0', '1', 'system:dict:add',         '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1027, '字典修改', 105, 3,  '#', '',  'F', '0', '1', 'system:dict:edit',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1028, '字典删除', 105, 4,  '#', '',  'F', '0', '1', 'system:dict:remove',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1029, '字典导出', 105, 5,  '#', '',  'F', '0', '1', 'system:dict:export',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 参数设置按钮
INSERT INTO SYS_MENU VALUES(1030, '参数查询', 106, 1,  '#', '',  'F', '0', '1', 'system:config:list',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1031, '参数新增', 106, 2,  '#', '',  'F', '0', '1', 'system:config:add',       '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1032, '参数修改', 106, 3,  '#', '',  'F', '0', '1', 'system:config:edit',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1033, '参数删除', 106, 4,  '#', '',  'F', '0', '1', 'system:config:remove',    '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1034, '参数导出', 106, 5,  '#', '',  'F', '0', '1', 'system:config:export',    '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 通知公告按钮
INSERT INTO SYS_MENU VALUES(1035, '公告查询', 107, 1,  '#', '',  'F', '0', '1', 'system:notice:list',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1036, '公告新增', 107, 2,  '#', '',  'F', '0', '1', 'system:notice:add',       '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1037, '公告修改', 107, 3,  '#', '',  'F', '0', '1', 'system:notice:edit',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1038, '公告删除', 107, 4,  '#', '',  'F', '0', '1', 'system:notice:remove',    '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 操作日志按钮
INSERT INTO SYS_MENU VALUES(1039, '操作查询', 500, 1,  '#', '',  'F', '0', '1', 'monitor:operlog:list',    '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1040, '操作删除', 500, 2,  '#', '',  'F', '0', '1', 'monitor:operlog:remove',  '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1041, '详细信息', 500, 3,  '#', '',  'F', '0', '1', 'monitor:operlog:detail',  '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1042, '日志导出', 500, 4,  '#', '',  'F', '0', '1', 'monitor:operlog:export',  '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 登录日志按钮
INSERT INTO SYS_MENU VALUES(1043, '登录查询', 501, 1,  '#', '',  'F', '0', '1', 'monitor:logininfor:list',         '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1044, '登录删除', 501, 2,  '#', '',  'F', '0', '1', 'monitor:logininfor:remove',       '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1045, '日志导出', 501, 3,  '#', '',  'F', '0', '1', 'monitor:logininfor:export',       '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1046, '账户解锁', 501, 4,  '#', '',  'F', '0', '1', 'monitor:logininfor:unlock',       '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 在线用户按钮
INSERT INTO SYS_MENU VALUES(1047, '在线查询', 109, 1,  '#', '',  'F', '0', '1', 'monitor:online:list',             '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1048, '批量强退', 109, 2,  '#', '',  'F', '0', '1', 'monitor:online:batchforcelogout', '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1049, '单条强退', 109, 3,  '#', '',  'F', '0', '1', 'monitor:online:forcelogout',      '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 定时任务按钮
INSERT INTO SYS_MENU VALUES(1050, '任务查询', 110, 1,  '#', '',  'F', '0', '1', 'monitor:job:list',                '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1051, '任务新增', 110, 2,  '#', '',  'F', '0', '1', 'monitor:job:add',                 '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1052, '任务修改', 110, 3,  '#', '',  'F', '0', '1', 'monitor:job:edit',                '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1053, '任务删除', 110, 4,  '#', '',  'F', '0', '1', 'monitor:job:remove',              '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1054, '状态修改', 110, 5,  '#', '',  'F', '0', '1', 'monitor:job:changestatus',        '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1055, '任务详细', 110, 6,  '#', '',  'F', '0', '1', 'monitor:job:detail',              '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1056, '任务导出', 110, 7,  '#', '',  'F', '0', '1', 'monitor:job:export',              '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
-- 代码生成按钮
INSERT INTO SYS_MENU VALUES(1057, '生成查询', 115, 1,  '#', '',  'F', '0', '1', 'tool:gen:list',     '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1058, '生成修改', 115, 2,  '#', '',  'F', '0', '1', 'tool:gen:edit',     '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1059, '生成删除', 115, 3,  '#', '',  'F', '0', '1', 'tool:gen:remove',   '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1060, '预览代码', 115, 4,  '#', '',  'F', '0', '1', 'tool:gen:preview',  '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');
INSERT INTO SYS_MENU VALUES(1061, '生成代码', 115, 5,  '#', '',  'F', '0', '1', 'tool:gen:code',     '#', 'admin', CURRENT TIMESTAMP, '', NULL, '');


-- ----------------------------
-- 6、用户和角色关联表  用户N-1角色
-- ----------------------------
CREATE TABLE SYS_USER_ROLE (
  USER_ID 	BIGINT  NOT NULL,
  ROLE_ID 	BIGINT  NOT NULL
);

ALTER TABLE SYS_USER_ROLE ADD CONSTRAINT PK_SYS_USER_ROLE PRIMARY KEY (USER_ID, ROLE_ID);

COMMENT ON TABLE  SYS_USER_ROLE              IS '用户和角色关联表';
COMMENT ON COLUMN SYS_USER_ROLE.USER_ID      IS '用户ID';
COMMENT ON COLUMN SYS_USER_ROLE.ROLE_ID      IS '角色ID';

-- ----------------------------
-- 初始化-用户和角色关联表数据
-- ----------------------------
INSERT INTO SYS_USER_ROLE VALUES (1, 1);
INSERT INTO SYS_USER_ROLE VALUES (2, 2);


-- ----------------------------
-- 7、角色和菜单关联表  角色1-N菜单
-- ----------------------------
CREATE TABLE SYS_ROLE_MENU (
  ROLE_ID 	BIGINT  NOT NULL,
  MENU_ID 	BIGINT  NOT NULL
);

ALTER TABLE SYS_ROLE_MENU ADD CONSTRAINT PK_SYS_ROLE_MENU PRIMARY KEY (ROLE_ID, MENU_ID);

COMMENT ON TABLE  SYS_ROLE_MENU              IS '角色和菜单关联表';
COMMENT ON COLUMN SYS_ROLE_MENU.ROLE_ID      IS '角色ID';
COMMENT ON COLUMN SYS_ROLE_MENU.MENU_ID      IS '菜单ID';

-- ----------------------------
-- 初始化-角色和菜单关联表数据
-- ----------------------------
INSERT INTO SYS_ROLE_MENU VALUES (2, 1);
INSERT INTO SYS_ROLE_MENU VALUES (2, 2);
INSERT INTO SYS_ROLE_MENU VALUES (2, 3);
INSERT INTO SYS_ROLE_MENU VALUES (2, 4);
INSERT INTO SYS_ROLE_MENU VALUES (2, 100);
INSERT INTO SYS_ROLE_MENU VALUES (2, 101);
INSERT INTO SYS_ROLE_MENU VALUES (2, 102);
INSERT INTO SYS_ROLE_MENU VALUES (2, 103);
INSERT INTO SYS_ROLE_MENU VALUES (2, 104);
INSERT INTO SYS_ROLE_MENU VALUES (2, 105);
INSERT INTO SYS_ROLE_MENU VALUES (2, 106);
INSERT INTO SYS_ROLE_MENU VALUES (2, 107);
INSERT INTO SYS_ROLE_MENU VALUES (2, 108);
INSERT INTO SYS_ROLE_MENU VALUES (2, 109);
INSERT INTO SYS_ROLE_MENU VALUES (2, 110);
INSERT INTO SYS_ROLE_MENU VALUES (2, 111);
INSERT INTO SYS_ROLE_MENU VALUES (2, 112);
INSERT INTO SYS_ROLE_MENU VALUES (2, 113);
INSERT INTO SYS_ROLE_MENU VALUES (2, 114);
INSERT INTO SYS_ROLE_MENU VALUES (2, 115);
INSERT INTO SYS_ROLE_MENU VALUES (2, 116);
INSERT INTO SYS_ROLE_MENU VALUES (2, 500);
INSERT INTO SYS_ROLE_MENU VALUES (2, 501);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1000);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1001);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1002);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1003);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1004);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1005);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1006);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1007);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1008);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1009);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1010);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1011);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1012);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1013);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1014);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1015);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1016);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1017);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1018);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1019);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1020);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1021);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1022);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1023);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1024);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1025);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1026);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1027);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1028);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1029);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1030);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1031);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1032);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1033);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1034);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1035);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1036);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1037);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1038);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1039);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1040);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1041);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1042);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1043);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1044);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1045);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1046);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1047);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1048);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1049);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1050);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1051);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1052);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1053);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1054);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1055);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1056);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1057);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1058);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1059);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1060);
INSERT INTO SYS_ROLE_MENU VALUES (2, 1061);

-- ----------------------------
-- 8、角色和部门关联表  角色1-N部门
-- ----------------------------
CREATE TABLE SYS_ROLE_DEPT (
  ROLE_ID 	BIGINT  NOT NULL,
  DEPT_ID 	BIGINT  NOT NULL
);

ALTER TABLE SYS_ROLE_DEPT ADD CONSTRAINT PK_SYS_ROLE_DEPT PRIMARY KEY (ROLE_ID, DEPT_ID);

COMMENT ON TABLE  SYS_ROLE_DEPT              IS '角色和部门关联表';
COMMENT ON COLUMN SYS_ROLE_DEPT.ROLE_ID      IS '角色ID';
COMMENT ON COLUMN SYS_ROLE_DEPT.DEPT_ID      IS '部门ID';

-- ----------------------------
-- 初始化-角色和部门关联表数据
-- ----------------------------
INSERT INTO SYS_ROLE_DEPT VALUES (2, 100);
INSERT INTO SYS_ROLE_DEPT VALUES (2, 101);
INSERT INTO SYS_ROLE_DEPT VALUES (2, 105);

-- ----------------------------
-- 9、用户与岗位关联表  用户1-N岗位
-- ----------------------------
CREATE TABLE SYS_USER_POST
(
	USER_ID BIGINT  NOT NULL,
	POST_ID BIGINT  NOT NULL
);

ALTER TABLE SYS_USER_POST ADD CONSTRAINT PK_SYS_USER_POST PRIMARY KEY (USER_ID, POST_ID);

COMMENT ON TABLE  SYS_USER_POST              IS '用户与岗位关联表';
COMMENT ON COLUMN SYS_USER_POST.USER_ID      IS '用户ID';
COMMENT ON COLUMN SYS_USER_POST.POST_ID      IS '岗位ID';

-- ----------------------------
-- 初始化-用户与岗位关联表数据
-- ----------------------------
INSERT INTO SYS_USER_POST VALUES (1, 1);
INSERT INTO SYS_USER_POST VALUES (2, 2);


-- ----------------------------
-- 10、操作日志记录
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_OPER_LOG
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_OPER_LOG (
  OPER_ID           BIGINT      NOT NULL ,
  TITLE             VARCHAR(50)    DEFAULT '',
  BUSINESS_TYPE     INTEGER       DEFAULT 0,
  METHOD            VARCHAR(100)   DEFAULT '',
  REQUEST_METHOD    VARCHAR(10)     DEFAULT '',
  OPERATOR_TYPE     INTEGER       DEFAULT 0,
  OPER_NAME         VARCHAR(50)    DEFAULT '',
  DEPT_NAME         VARCHAR(50)    DEFAULT '',
  OPER_URL          VARCHAR(255) 	DEFAULT '',
  OPER_IP           VARCHAR(128)   DEFAULT '',
  OPER_LOCATION     VARCHAR(255)   DEFAULT '',
  OPER_PARAM        VARCHAR(2000)  DEFAULT '',
  JSON_RESULT       VARCHAR(2000)  DEFAULT '',
  STATUS            INTEGER       DEFAULT 0,
  ERROR_MSG         VARCHAR(2000)  DEFAULT '' ,
  OPER_TIME         TIMESTAMP
);

ALTER TABLE SYS_OPER_LOG ADD CONSTRAINT PK_SYS_OPER_LOG PRIMARY KEY (OPER_ID);

COMMENT ON TABLE  SYS_OPER_LOG                IS '操作日志记录';
COMMENT ON COLUMN SYS_OPER_LOG.OPER_ID        IS '日志主键SEQ_SYS_OPER_LOG.NEXTVAL';
COMMENT ON COLUMN SYS_OPER_LOG.TITLE          IS '模块标题';
COMMENT ON COLUMN SYS_OPER_LOG.BUSINESS_TYPE  IS '业务类型（0其它 1新增 2修改 3删除）';
COMMENT ON COLUMN SYS_OPER_LOG.METHOD         IS '方法名称';
COMMENT ON COLUMN SYS_OPER_LOG.REQUEST_METHOD IS '请求方式';
COMMENT ON COLUMN SYS_OPER_LOG.OPERATOR_TYPE  IS '操作类别（0其它 1后台用户 2手机端用户）';
COMMENT ON COLUMN SYS_OPER_LOG.OPER_NAME      IS '操作人员';
COMMENT ON COLUMN SYS_OPER_LOG.DEPT_NAME      IS '部门名称';
COMMENT ON COLUMN SYS_OPER_LOG.OPER_URL       IS '请求URL';
COMMENT ON COLUMN SYS_OPER_LOG.OPER_IP        IS '主机地址';
COMMENT ON COLUMN SYS_OPER_LOG.OPER_LOCATION  IS '操作地点';
COMMENT ON COLUMN SYS_OPER_LOG.OPER_PARAM     IS '请求参数';
COMMENT ON COLUMN SYS_OPER_LOG.JSON_RESULT    IS '返回参数';
COMMENT ON COLUMN SYS_OPER_LOG.STATUS         IS '操作状态（0正常 1异常）';
COMMENT ON COLUMN SYS_OPER_LOG.ERROR_MSG      IS '错误消息';
COMMENT ON COLUMN SYS_OPER_LOG.OPER_TIME      IS '操作时间';


-- ----------------------------
-- 11、字典类型表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_DICT_TYPE
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_DICT_TYPE
(
  DICT_ID           BIGINT      NOT NULL,
  DICT_NAME         VARCHAR(100)   DEFAULT '',
  DICT_TYPE         VARCHAR(100)   DEFAULT '',
  STATUS            CHARACTER(1)         DEFAULT '0',
  CREATE_BY         VARCHAR(64)    DEFAULT '',
  CREATE_TIME       TIMESTAMP,
  UPDATE_BY         VARCHAR(64)    DEFAULT '',
  UPDATE_TIME       TIMESTAMP,
  REMARK            VARCHAR(500)   DEFAULT NULL
);

ALTER TABLE SYS_DICT_TYPE ADD CONSTRAINT PK_SYS_DICT_TYPE PRIMARY KEY (DICT_ID);
CREATE UNIQUE INDEX SYS_DICT_TYPE_INDEX1 ON SYS_DICT_TYPE (DICT_TYPE);

COMMENT ON TABLE  SYS_DICT_TYPE               IS '字典类型表';
COMMENT ON COLUMN SYS_DICT_TYPE.DICT_ID       IS '字典主键SEQ_SYS_DICT_TYPE.NEXTVAL';
COMMENT ON COLUMN SYS_DICT_TYPE.DICT_NAME     IS '字典名称';
COMMENT ON COLUMN SYS_DICT_TYPE.DICT_TYPE     IS '字典类型';
COMMENT ON COLUMN SYS_DICT_TYPE.STATUS        IS '状态（0正常 1停用）';
COMMENT ON COLUMN SYS_DICT_TYPE.CREATE_BY     IS '创建者';
COMMENT ON COLUMN SYS_DICT_TYPE.CREATE_TIME   IS '创建时间';
COMMENT ON COLUMN SYS_DICT_TYPE.UPDATE_BY     IS '更新者';
COMMENT ON COLUMN SYS_DICT_TYPE.UPDATE_TIME   IS '更新时间';
COMMENT ON COLUMN SYS_DICT_TYPE.REMARK        IS '备注';

INSERT INTO SYS_DICT_TYPE VALUES(1,  '用户性别', 'sys_user_sex',        '0', 'admin', CURRENT TIMESTAMP, '', NULL, '用户性别列表');
INSERT INTO SYS_DICT_TYPE VALUES(2,  '菜单状态', 'sys_show_hide',       '0', 'admin', CURRENT TIMESTAMP, '', NULL, '菜单状态列表');
INSERT INTO SYS_DICT_TYPE VALUES(3,  '系统开关', 'sys_normal_disable',  '0', 'admin', CURRENT TIMESTAMP, '', NULL, '系统开关列表');
INSERT INTO SYS_DICT_TYPE VALUES(4,  '任务状态', 'sys_job_status',      '0', 'admin', CURRENT TIMESTAMP, '', NULL, '任务状态列表');
INSERT INTO SYS_DICT_TYPE VALUES(5,  '任务分组', 'sys_job_group',       '0', 'admin', CURRENT TIMESTAMP, '', NULL, '任务分组列表');
INSERT INTO SYS_DICT_TYPE VALUES(6,  '系统是否', 'sys_yes_no',          '0', 'admin', CURRENT TIMESTAMP, '', NULL, '系统是否列表');
INSERT INTO SYS_DICT_TYPE VALUES(7,  '通知类型', 'sys_notice_type',     '0', 'admin', CURRENT TIMESTAMP, '', NULL, '通知类型列表');
INSERT INTO SYS_DICT_TYPE VALUES(8,  '通知状态', 'sys_notice_status',   '0', 'admin', CURRENT TIMESTAMP, '', NULL, '通知状态列表');
INSERT INTO SYS_DICT_TYPE VALUES(9,  '操作类型', 'sys_oper_type',       '0', 'admin', CURRENT TIMESTAMP, '', NULL, '操作类型列表');
INSERT INTO SYS_DICT_TYPE VALUES(10, '系统状态', 'sys_common_status',   '0', 'admin', CURRENT TIMESTAMP, '', NULL, '登录状态列表');


-- ----------------------------
-- 12、字典数据表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_DICT_DATA
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_DICT_DATA
(
  DICT_CODE        BIGINT      NOT NULL,
  DICT_SORT        INTEGER       DEFAULT 0,
  DICT_LABEL       VARCHAR(100)   DEFAULT '',
  DICT_VALUE       VARCHAR(100)   DEFAULT '',
  DICT_TYPE        VARCHAR(100)   DEFAULT '',
  CSS_CLASS        VARCHAR(100)   DEFAULT NULL,
  LIST_CLASS       VARCHAR(100)   DEFAULT NULL,
  IS_DEFAULT       CHARACTER(1)         DEFAULT 'N',
  STATUS           CHARACTER(1)         DEFAULT '0',
  CREATE_BY        VARCHAR(64)    DEFAULT '',
  CREATE_TIME      TIMESTAMP,
  UPDATE_BY        VARCHAR(64)    DEFAULT '',
  UPDATE_TIME      TIMESTAMP,
  REMARK           VARCHAR(500)   DEFAULT NULL
);

ALTER TABLE SYS_DICT_DATA ADD CONSTRAINT PK_SYS_DICT_DATA PRIMARY KEY (DICT_CODE);

COMMENT ON TABLE  SYS_DICT_DATA               IS '字典数据表';
COMMENT ON COLUMN SYS_DICT_DATA.DICT_CODE     IS '字典主键SEQ_SYS_DICT_DATA.NEXTVAL';
COMMENT ON COLUMN SYS_DICT_DATA.DICT_SORT     IS '字典排序';
COMMENT ON COLUMN SYS_DICT_DATA.DICT_LABEL    IS '字典标签';
COMMENT ON COLUMN SYS_DICT_DATA.DICT_VALUE    IS '字典键值';
COMMENT ON COLUMN SYS_DICT_DATA.DICT_TYPE     IS '字典类型';
COMMENT ON COLUMN SYS_DICT_DATA.CSS_CLASS     IS '样式属性（其他样式扩展）';
COMMENT ON COLUMN SYS_DICT_DATA.LIST_CLASS    IS '表格回显样式';
COMMENT ON COLUMN SYS_DICT_DATA.IS_DEFAULT    IS '是否默认（Y是 N否）';
COMMENT ON COLUMN SYS_DICT_DATA.STATUS        IS '状态（0正常 1停用）';
COMMENT ON COLUMN SYS_DICT_DATA.CREATE_BY     IS '创建者';
COMMENT ON COLUMN SYS_DICT_DATA.CREATE_TIME   IS '创建时间';
COMMENT ON COLUMN SYS_DICT_DATA.UPDATE_BY     IS '更新者';
COMMENT ON COLUMN SYS_DICT_DATA.UPDATE_TIME   IS '更新时间';
COMMENT ON COLUMN SYS_DICT_DATA.REMARK        IS '备注';

INSERT INTO SYS_DICT_DATA VALUES(1,  1,  '男',       '0',       'sys_user_sex',        '',   '',        'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '性别男');
INSERT INTO SYS_DICT_DATA VALUES(2,  2,  '女',       '1',       'sys_user_sex',        '',   '',        'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '性别女');
INSERT INTO SYS_DICT_DATA VALUES(3,  3,  '未知',     '2',       'sys_user_sex',        '',   '',        'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '性别未知');
INSERT INTO SYS_DICT_DATA VALUES(4,  1,  '显示',     '0',       'sys_show_hide',       '',   'primary', 'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '显示菜单');
INSERT INTO SYS_DICT_DATA VALUES(5,  2,  '隐藏',     '1',       'sys_show_hide',       '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '隐藏菜单');
INSERT INTO SYS_DICT_DATA VALUES(6,  1,  '正常',     '0',       'sys_normal_disable',  '',   'primary', 'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '正常状态');
INSERT INTO SYS_DICT_DATA VALUES(7,  2,  '停用',     '1',       'sys_normal_disable',  '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '停用状态');
INSERT INTO SYS_DICT_DATA VALUES(8,  1,  '正常',     '0',       'sys_job_status',      '',   'primary', 'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '正常状态');
INSERT INTO SYS_DICT_DATA VALUES(9,  2,  '暂停',     '1',       'sys_job_status',      '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '停用状态');
INSERT INTO SYS_DICT_DATA VALUES(10, 1,  '默认',     'DEFAULT', 'sys_job_group',       '',   '',        'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '默认分组');
INSERT INTO SYS_DICT_DATA VALUES(11, 2,  '系统',     'SYSTEM',  'sys_job_group',       '',   '',        'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '系统分组');
INSERT INTO SYS_DICT_DATA VALUES(12, 1,  '是',       'Y',       'sys_yes_no',          '',   'primary', 'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '系统默认是');
INSERT INTO SYS_DICT_DATA VALUES(13, 2,  '否',       'N',       'sys_yes_no',          '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '系统默认否');
INSERT INTO SYS_DICT_DATA VALUES(14, 1,  '通知',     '1',       'sys_notice_type',     '',   'warning', 'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '通知');
INSERT INTO SYS_DICT_DATA VALUES(15, 2,  '公告',     '2',       'sys_notice_type',     '',   'success', 'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '公告');
INSERT INTO SYS_DICT_DATA VALUES(16, 1,  '正常',     '0',       'sys_notice_status',   '',   'primary', 'Y', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '正常状态');
INSERT INTO SYS_DICT_DATA VALUES(17, 2,  '关闭',     '1',       'sys_notice_status',   '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '关闭状态');
INSERT INTO SYS_DICT_DATA VALUES(18, 99, '其他',     '0',       'sys_oper_type',       '',   'info',    'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '其他操作');
INSERT INTO SYS_DICT_DATA VALUES(19, 1,  '新增',     '1',       'sys_oper_type',       '',   'info',    'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '新增操作');
INSERT INTO SYS_DICT_DATA VALUES(20, 2,  '修改',     '2',       'sys_oper_type',       '',   'info',    'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '修改操作');
INSERT INTO SYS_DICT_DATA VALUES(21, 3,  '删除',     '3',       'sys_oper_type',       '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '删除操作');
INSERT INTO SYS_DICT_DATA VALUES(22, 4,  '授权',     '4',       'sys_oper_type',       '',   'primary', 'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '授权操作');
INSERT INTO SYS_DICT_DATA VALUES(23, 5,  '导出',     '5',       'sys_oper_type',       '',   'warning', 'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '导出操作');
INSERT INTO SYS_DICT_DATA VALUES(24, 6,  '导入',     '6',       'sys_oper_type',       '',   'warning', 'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '导入操作');
INSERT INTO SYS_DICT_DATA VALUES(25, 7,  '强退',     '7',       'sys_oper_type',       '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '强退操作');
INSERT INTO SYS_DICT_DATA VALUES(26, 8,  '生成代码', '8',       'sys_oper_type',       '',   'warning', 'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '生成操作');
INSERT INTO SYS_DICT_DATA VALUES(27, 9,  '清空数据', '9',       'sys_oper_type',       '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '清空操作');
INSERT INTO SYS_DICT_DATA VALUES(28, 1,  '成功',     '0',       'sys_common_status',   '',   'primary', 'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '正常状态');
INSERT INTO SYS_DICT_DATA VALUES(29, 2,  '失败',     '1',       'sys_common_status',   '',   'danger',  'N', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '停用状态');


-- ----------------------------
-- 13、参数配置表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_CONFIG
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_CONFIG (
  CONFIG_ID         BIGINT     NOT NULL,
  CONFIG_NAME       VARCHAR(100)  DEFAULT '',
  CONFIG_KEY        VARCHAR(100)  DEFAULT '',
  CONFIG_VALUE      VARCHAR(100)  DEFAULT '',
  CONFIG_TYPE       CHARACTER(1)        DEFAULT 'N',
  CREATE_BY         VARCHAR(64)   DEFAULT '',
  CREATE_TIME       TIMESTAMP,
  UPDATE_BY         VARCHAR(64)   DEFAULT '',
  UPDATE_TIME       TIMESTAMP,
  REMARK            VARCHAR(500)  DEFAULT NULL
);
ALTER TABLE SYS_CONFIG ADD CONSTRAINT PK_SYS_CONFIG PRIMARY KEY (CONFIG_ID);

COMMENT ON TABLE  SYS_CONFIG               IS '参数配置表';
COMMENT ON COLUMN SYS_CONFIG.CONFIG_ID     IS '参数主键SEQ_SYS_CONFIG.NEXTVAL';
COMMENT ON COLUMN SYS_CONFIG.CONFIG_NAME   IS '参数名称';
COMMENT ON COLUMN SYS_CONFIG.CONFIG_KEY    IS '参数键名';
COMMENT ON COLUMN SYS_CONFIG.CONFIG_VALUE  IS '参数键值';
COMMENT ON COLUMN SYS_CONFIG.CONFIG_TYPE   IS '系统内置（Y是 N否）';
COMMENT ON COLUMN SYS_CONFIG.CREATE_BY     IS '创建者';
COMMENT ON COLUMN SYS_CONFIG.CREATE_TIME   IS '创建时间';
COMMENT ON COLUMN SYS_CONFIG.UPDATE_BY     IS '更新者';
COMMENT ON COLUMN SYS_CONFIG.UPDATE_TIME   IS '更新时间';
COMMENT ON COLUMN SYS_CONFIG.REMARK        IS '备注';

INSERT INTO SYS_CONFIG VALUES(1, '主框架页-默认皮肤样式名称',     'sys.index.skinname',               'skin-blue',     'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow');
INSERT INTO SYS_CONFIG VALUES(2, '用户管理-账号初始密码',         'sys.user.initpassword',            '123456',        'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '初始化密码 123456');
INSERT INTO SYS_CONFIG VALUES(3, '主框架页-侧边栏主题',           'sys.index.sidetheme',              'theme-dark',    'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '深黑主题theme-dark，浅色主题theme-light，深蓝主题theme-blue');
INSERT INTO SYS_CONFIG VALUES(4, '账号自助-是否开启用户注册功能', 'Sys.account.registeruser',         'false',         'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '是否开启注册用户功能（true开启，false关闭）');
INSERT INTO SYS_CONFIG VALUES(5, '用户管理-密码字符范围',         'sys.account.chrtype',              '0',             'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '默认任意字符范围，0任意（密码可以输入任意字符），1数字（密码只能为0-9数字），2英文字母（密码只能为a-z和字A-Z母），3字母和数字（密码必须包含字母，数字）,4字母数字和特殊字符（目前支持的特殊字符包括：~!@#$%^&*()-=_+）');
INSERT INTO SYS_CONFIG VALUES(6, '用户管理-初始密码修改策略',     'sys.account.initpasswordmodify',   '0',             'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '0：初始密码修改策略关闭，没有任何提示，1：提醒用户，如果未修改初始密码，则在登录时就会提醒修改密码对话框');
INSERT INTO SYS_CONFIG VALUES(7, '用户管理-账号密码更新周期',     'sys.account.passwordvalidatedays', '0',             'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '密码更新周期（填写数字，数据初始化值为0不限制，若修改必须为大于0小于365的正整数），如果超过这个周期登录系统时，则在登录时就会提醒修改密码对话框');
INSERT INTO SYS_CONFIG VALUES(8, '主框架页-菜单导航显示风格',     'sys.index.menustyle',              'default',       'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '菜单导航显示风格（default为左侧导航菜单，topnav为顶部导航菜单）');
INSERT INTO SYS_CONFIG VALUES(9, '主框架页-是否开启页脚',         'sys.index.ignorefooter',           'true',          'Y', 'admin', CURRENT TIMESTAMP, '', NULL, '是否开启底部页脚显示（true显示，false隐藏）');


-- ----------------------------
-- 14、系统访问记录
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_LOGININFOR
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_LOGININFOR (
  INFO_ID         BIGINT     NOT NULL,
  LOGIN_NAME      VARCHAR(50)   DEFAULT '',
  IPADDR          VARCHAR(128)  DEFAULT '',
  LOGIN_LOCATION  VARCHAR(255)  DEFAULT '',
  BROWSER         VARCHAR(50)   DEFAULT '',
  OS              VARCHAR(50)   DEFAULT '',
  STATUS          CHARACTER(1)        DEFAULT '0',
  MSG             VARCHAR(255)  DEFAULT '',
  LOGIN_TIME      TIMESTAMP
);

ALTER TABLE SYS_LOGININFOR ADD CONSTRAINT PK_SYS_LOGININFOR PRIMARY KEY (INFO_ID);

COMMENT ON TABLE  SYS_LOGININFOR                IS '系统访问记录';
COMMENT ON COLUMN SYS_LOGININFOR.INFO_ID        IS '访问主键SEQ_SEQ_SYS_LOGININFOR.NEXTVAL';
COMMENT ON COLUMN SYS_LOGININFOR.LOGIN_NAME     IS '登录账号';
COMMENT ON COLUMN SYS_LOGININFOR.IPADDR         IS '登录IP地址';
COMMENT ON COLUMN SYS_LOGININFOR.LOGIN_LOCATION IS '登录地点';
COMMENT ON COLUMN SYS_LOGININFOR.BROWSER        IS '浏览器类型';
COMMENT ON COLUMN SYS_LOGININFOR.OS             IS '操作系统';
COMMENT ON COLUMN SYS_LOGININFOR.STATUS         IS '登录状态（0成功 1失败）';
COMMENT ON COLUMN SYS_LOGININFOR.MSG            IS '提示消息';
COMMENT ON COLUMN SYS_LOGININFOR.LOGIN_TIME     IS '访问时间';

-- ----------------------------
-- 15、在线用户记录
-- ----------------------------
CREATE TABLE SYS_USER_ONLINE (
  SESSIONID         VARCHAR(50)  NOT NULL,
  LOGIN_NAME        VARCHAR(50)  DEFAULT '',
  DEPT_NAME         VARCHAR(50)  DEFAULT '',
  IPADDR            VARCHAR(128) DEFAULT '',
  LOGIN_LOCATION    VARCHAR(255) DEFAULT '',
  BROWSER           VARCHAR(50)  DEFAULT '',
  OS                VARCHAR(50)  DEFAULT '',
  STATUS            VARCHAR(10)  DEFAULT '',
  START_TIMESTAMP   TIMESTAMP,
  LAST_ACCESS_TIME  TIMESTAMP,
  EXPIRE_TIME       BIGINT    DEFAULT 0
);

ALTER TABLE SYS_USER_ONLINE ADD CONSTRAINT PK_SYS_USER_ONLINE PRIMARY KEY (SESSIONID);

COMMENT ON TABLE  SYS_USER_ONLINE                   IS '在线用户记录';
COMMENT ON COLUMN SYS_USER_ONLINE.SESSIONID         IS '用户会话ID';
COMMENT ON COLUMN SYS_USER_ONLINE.LOGIN_NAME        IS '登录账号';
COMMENT ON COLUMN SYS_USER_ONLINE.DEPT_NAME         IS '部门名称';
COMMENT ON COLUMN SYS_USER_ONLINE.IPADDR            IS '登录IP地址';
COMMENT ON COLUMN SYS_USER_ONLINE.LOGIN_LOCATION    IS '登录地点';
COMMENT ON COLUMN SYS_USER_ONLINE.BROWSER           IS '浏览器类型';
COMMENT ON COLUMN SYS_USER_ONLINE.OS                IS '操作系统';
COMMENT ON COLUMN SYS_USER_ONLINE.STATUS            IS '在线状态ON_LINE在线OFF_LINE离线';
COMMENT ON COLUMN SYS_USER_ONLINE.START_TIMESTAMP   IS 'SESSION创建时间';
COMMENT ON COLUMN SYS_USER_ONLINE.LAST_ACCESS_TIME  IS 'SESSION最后访问时间';
COMMENT ON COLUMN SYS_USER_ONLINE.EXPIRE_TIME       IS '超时时间，单位为分钟';

-- ----------------------------
-- 16、定时任务调度表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_JOB
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_JOB (
     JOB_ID              BIGINT     NOT NULL,
     JOB_NAME            VARCHAR(64)  NOT NULL ,
     JOB_GROUP           VARCHAR(64)    NOT NULL ,
     INVOKE_TARGET       VARCHAR(500)  NOT NULL ,
     CRON_EXPRESSION     VARCHAR(255)  DEFAULT '',
     MISFIRE_POLICY      VARCHAR(20)   DEFAULT '3',
     CONCURRENT          CHARACTER(1)        DEFAULT '1',
     STATUS              CHARACTER(1)        DEFAULT '0',
     CREATE_BY           VARCHAR(64)   DEFAULT '',
     CREATE_TIME         TIMESTAMP,
     UPDATE_BY           VARCHAR(64)   DEFAULT '',
     UPDATE_TIME         TIMESTAMP,
     REMARK              VARCHAR(500)  DEFAULT ''
);

ALTER TABLE SYS_JOB ADD CONSTRAINT PK_SYS_JOB PRIMARY KEY (JOB_ID, JOB_NAME, JOB_GROUP);

COMMENT ON TABLE  SYS_JOB                   IS '定时任务调度表';
COMMENT ON COLUMN SYS_JOB.JOB_ID            IS '任务主键SEQ_SYS_JOB.NEXTVAL';
COMMENT ON COLUMN SYS_JOB.JOB_NAME          IS '任务名称';
COMMENT ON COLUMN SYS_JOB.JOB_GROUP         IS '任务组名';
COMMENT ON COLUMN SYS_JOB.INVOKE_TARGET     IS '调用目标字符串';
COMMENT ON COLUMN SYS_JOB.CRON_EXPRESSION   IS 'CRON执行表达式';
COMMENT ON COLUMN SYS_JOB.MISFIRE_POLICY    IS '计划执行错误策略（1立即执行 2执行一次 3放弃执行）';
COMMENT ON COLUMN SYS_JOB.CONCURRENT        IS '是否并发执行（0允许 1禁止）';
COMMENT ON COLUMN SYS_JOB.STATUS            IS '状态（0正常 1暂停）';
COMMENT ON COLUMN SYS_JOB.CREATE_BY         IS '创建者';
COMMENT ON COLUMN SYS_JOB.CREATE_TIME       IS '创建时间';
COMMENT ON COLUMN SYS_JOB.UPDATE_BY         IS '更新者';
COMMENT ON COLUMN SYS_JOB.UPDATE_TIME       IS '更新时间';
COMMENT ON COLUMN SYS_JOB.REMARK            IS '备注信息';

INSERT INTO SYS_JOB VALUES(1, '系统默认（无参）', 'DEFAULT', 'ryTask.ryNoParams',        '0/10 * * * * ?', '3', '1', '1', 'admin', CURRENT TIMESTAMP, '', null, '');
INSERT INTO SYS_JOB VALUES(2, '系统默认（有参）', 'DEFAULT', 'ryTask.ryParams(''ry'')',  '0/15 * * * * ?', '3', '1', '1', 'admin', CURRENT TIMESTAMP, '', null, '');
INSERT INTO SYS_JOB VALUES(3, '系统默认（多参）', 'DEFAULT', 'ryTask.ryMultipleParams(''ry'', true, 2000L, 316.50D, 100)',  '0/20 * * * * ?', '3', '1', '1', 'admin', CURRENT TIMESTAMP, '', null, '');

-- ----------------------------
-- 17、定时任务调度日志表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_JOB_LOG
 INCREMENT BY 1
 START WITH 1
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_JOB_LOG (
  JOB_LOG_ID          BIGINT       NOT NULL,
  JOB_NAME            VARCHAR(64)     NOT NULL,
  JOB_GROUP           VARCHAR(64)     NOT NULL,
  INVOKE_TARGET       VARCHAR(500)    NOT NULL ,
  JOB_MESSAGE         VARCHAR(500),
  STATUS              CHARACTER(1)          DEFAULT '0',
  EXCEPTION_INFO      VARCHAR(2000)   DEFAULT '',
  CREATE_TIME         TIMESTAMP
);

ALTER TABLE SYS_JOB_LOG ADD CONSTRAINT PK_SYS_JOB_LOG PRIMARY KEY (JOB_LOG_ID);

COMMENT ON TABLE  SYS_JOB_LOG                   IS '定时任务调度日志表';
COMMENT ON COLUMN SYS_JOB_LOG.JOB_LOG_ID        IS '日志主键SEQ_SYS_JOB_LOG.NEXTVAL';
COMMENT ON COLUMN SYS_JOB_LOG.JOB_NAME          IS '任务名称';
COMMENT ON COLUMN SYS_JOB_LOG.JOB_GROUP         IS '任务组名';
COMMENT ON COLUMN SYS_JOB_LOG.INVOKE_TARGET     IS '调用目标字符串';
COMMENT ON COLUMN SYS_JOB_LOG.JOB_MESSAGE       IS '日志信息';
COMMENT ON COLUMN SYS_JOB_LOG.STATUS            IS '执行状态（0正常 1失败）';
COMMENT ON COLUMN SYS_JOB_LOG.EXCEPTION_INFO    IS '异常信息';
COMMENT ON COLUMN SYS_JOB_LOG.CREATE_TIME       IS '创建时间';


-- ----------------------------
-- 18、通知公告表
-- ----------------------------
CREATE SEQUENCE SEQ_SYS_NOTICE
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE SYS_NOTICE (
  NOTICE_ID         BIGINT      NOT NULL,
  NOTICE_TITLE      VARCHAR(50)    NOT NULL,
  NOTICE_TYPE       CHARACTER(1)         NOT NULL,
  NOTICE_CONTENT    VARCHAR(2000)  DEFAULT NULL,
  STATUS            CHARACTER(1)         DEFAULT '0',
  CREATE_BY         VARCHAR(64)    DEFAULT '',
  CREATE_TIME       TIMESTAMP,
  UPDATE_BY         VARCHAR(64)    DEFAULT '',
  UPDATE_TIME       TIMESTAMP,
  REMARK            VARCHAR(255)   DEFAULT NULL
);

ALTER TABLE SYS_NOTICE ADD CONSTRAINT PK_SYS_NOTICE PRIMARY KEY (NOTICE_ID);

COMMENT ON TABLE  SYS_NOTICE                   IS '通知公告表';
COMMENT ON COLUMN SYS_NOTICE.NOTICE_ID         IS '公告主键SEQ_SYS_NOTICE.NEXTVAL';
COMMENT ON COLUMN SYS_NOTICE.NOTICE_TITLE      IS '公告标题';
COMMENT ON COLUMN SYS_NOTICE.NOTICE_TYPE       IS '公告类型（1通知 2公告）';
COMMENT ON COLUMN SYS_NOTICE.NOTICE_CONTENT    IS '公告内容';
COMMENT ON COLUMN SYS_NOTICE.STATUS            IS '公告状态（0正常 1关闭）';
COMMENT ON COLUMN SYS_NOTICE.CREATE_BY         IS '创建者';
COMMENT ON COLUMN SYS_NOTICE.CREATE_TIME       IS '创建时间';
COMMENT ON COLUMN SYS_NOTICE.UPDATE_BY         IS '更新者';
COMMENT ON COLUMN SYS_NOTICE.UPDATE_TIME       IS '更新时间';
COMMENT ON COLUMN SYS_NOTICE.REMARK            IS '备注';

-- ----------------------------
-- 初始化-公告信息表数据
-- ----------------------------
INSERT INTO SYS_NOTICE VALUES(1, '温馨提醒：2018-07-01 若依新版本发布啦', '2', '新版本内容', '0', 'admin', CURRENT TIMESTAMP, '', NULL, '管理员');
INSERT INTO SYS_NOTICE VALUES(2, '维护通知：2018-07-01 若依系统凌晨维护', '1', '维护内容',   '0', 'admin', CURRENT TIMESTAMP, '', NULL, '管理员');
COMMIT;


-- ----------------------------
-- 19、代码生成业务表
-- ----------------------------
CREATE SEQUENCE SEQ_GEN_TABLE
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;

CREATE TABLE GEN_TABLE (
  TABLE_ID           BIGINT       NOT NULL,
  TABLE_NAME         VARCHAR(200)    DEFAULT '',
  TABLE_COMMENT      VARCHAR(500)    DEFAULT '',
  SUB_TABLE_NAME     VARCHAR(64)      DEFAULT NULL,
  SUB_TABLE_FK_NAME  VARCHAR(64)      DEFAULT NULL,
  CLASS_NAME         VARCHAR(100)    DEFAULT '',
  TPL_CATEGORY       VARCHAR(200)    DEFAULT 'CRUD',
  PACKAGE_NAME       VARCHAR(100),
  MODULE_NAME        VARCHAR(30),
  BUSINESS_NAME      VARCHAR(30),
  FUNCTION_NAME      VARCHAR(50),
  FUNCTION_AUTHOR    VARCHAR(50),
  GEN_TYPE           CHARACTER(1)          DEFAULT '0',
  GEN_PATH           VARCHAR(200)    DEFAULT '/',
  OPTIONS            VARCHAR(1000),
  CREATE_BY          VARCHAR(64)     DEFAULT '',
  CREATE_TIME        TIMESTAMP,
  UPDATE_BY          VARCHAR(64)     DEFAULT '',
  UPDATE_TIME        TIMESTAMP,
  REMARK             VARCHAR(500)    DEFAULT NULL
);

ALTER TABLE GEN_TABLE ADD CONSTRAINT PK_GEN_TABLE PRIMARY KEY (TABLE_ID);

COMMENT ON TABLE  GEN_TABLE                          IS '代码生成业务表';
COMMENT ON COLUMN GEN_TABLE.TABLE_ID                 IS '编号';
COMMENT ON COLUMN GEN_TABLE.TABLE_NAME               IS '表名称';
COMMENT ON COLUMN GEN_TABLE.TABLE_COMMENT            IS '表描述';
COMMENT ON COLUMN GEN_TABLE.SUB_TABLE_NAME           IS '关联子表的表名';
COMMENT ON COLUMN GEN_TABLE.SUB_TABLE_FK_NAME        IS '子表关联的外键名';
COMMENT ON COLUMN GEN_TABLE.CLASS_NAME               IS '实体类名称';
COMMENT ON COLUMN GEN_TABLE.TPL_CATEGORY             IS '使用的模板（CRUD单表操作 TREE树表操作 SUB主子表操作）';
COMMENT ON COLUMN GEN_TABLE.PACKAGE_NAME             IS '生成包路径';
COMMENT ON COLUMN GEN_TABLE.MODULE_NAME              IS '生成模块名';
COMMENT ON COLUMN GEN_TABLE.BUSINESS_NAME            IS '生成业务名';
COMMENT ON COLUMN GEN_TABLE.FUNCTION_NAME            IS '生成功能名';
COMMENT ON COLUMN GEN_TABLE.FUNCTION_AUTHOR          IS '生成功能作者';
COMMENT ON COLUMN GEN_TABLE.GEN_TYPE                 IS '生成代码方式（0ZIP压缩包 1自定义路径）';
COMMENT ON COLUMN GEN_TABLE.GEN_PATH                 IS '生成路径（不填默认项目路径）';
COMMENT ON COLUMN GEN_TABLE.OPTIONS                  IS '其它生成选项';
COMMENT ON COLUMN GEN_TABLE.CREATE_BY                IS '创建者';
COMMENT ON COLUMN GEN_TABLE.CREATE_TIME              IS '创建时间';
COMMENT ON COLUMN GEN_TABLE.UPDATE_BY                IS '更新者';
COMMENT ON COLUMN GEN_TABLE.UPDATE_TIME              IS '更新时间';
COMMENT ON COLUMN GEN_TABLE.REMARK                   IS '备注';


-- ----------------------------
-- 20、代码生成业务表字段
-- ----------------------------
CREATE SEQUENCE SEQ_GEN_TABLE_COLUMN
 INCREMENT BY 1
 START WITH 100
 NOMAXVALUE
 NOMINVALUE
 CACHE 20;
CREATE TABLE GEN_TABLE_COLUMN (
  COLUMN_ID          BIGINT      NOT NULL,
  TABLE_ID           BIGINT      NOT NULL,
  COLUMN_NAME        VARCHAR(200),
  COLUMN_COMMENT     VARCHAR(500),
  COLUMN_TYPE        VARCHAR(100),
  JAVA_TYPE          VARCHAR(500),
  JAVA_FIELD         VARCHAR(200),
  IS_PK              CHARACTER(1),
  IS_INCREMENT       CHARACTER(1),
  IS_REQUIRED        CHARACTER(1),
  IS_INSERT          CHARACTER(1),
  IS_EDIT            CHARACTER(1),
  IS_LIST            CHARACTER(1),
  IS_QUERY           CHARACTER(1),
  QUERY_TYPE         VARCHAR(200)    DEFAULT 'EQ',
  HTML_TYPE          VARCHAR(200),
  DICT_TYPE          VARCHAR(200)    DEFAULT '',
  SORT               INTEGER,
  CREATE_BY          VARCHAR(64)     DEFAULT '',
  CREATE_TIME        TIMESTAMP ,
  UPDATE_BY          VARCHAR(64)     DEFAULT '',
  UPDATE_TIME        TIMESTAMP
);

ALTER TABLE GEN_TABLE_COLUMN ADD CONSTRAINT PK_GEN_TABLE_CO PRIMARY KEY (COLUMN_ID);

COMMENT ON TABLE  GEN_TABLE_COLUMN                   IS '代码生成业务表字段';
COMMENT ON COLUMN GEN_TABLE_COLUMN.COLUMN_ID         IS '编号';
COMMENT ON COLUMN GEN_TABLE_COLUMN.TABLE_ID          IS '归属表编号';
COMMENT ON COLUMN GEN_TABLE_COLUMN.COLUMN_NAME       IS '列名称';
COMMENT ON COLUMN GEN_TABLE_COLUMN.COLUMN_COMMENT    IS '列描述';
COMMENT ON COLUMN GEN_TABLE_COLUMN.COLUMN_TYPE       IS '列类型';
COMMENT ON COLUMN GEN_TABLE_COLUMN.JAVA_TYPE         IS 'JAVA类型';
COMMENT ON COLUMN GEN_TABLE_COLUMN.JAVA_FIELD        IS 'JAVA字段名';
COMMENT ON COLUMN GEN_TABLE_COLUMN.IS_PK             IS '是否主键（1是）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.IS_INCREMENT      IS '是否自增（1是）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.IS_REQUIRED       IS '是否必填（1是）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.IS_INSERT         IS '是否为插入字段（1是）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.IS_EDIT           IS '是否编辑字段（1是）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.IS_LIST           IS '是否列表字段（1是）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.IS_QUERY          IS '是否查询字段（1是）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.QUERY_TYPE        IS '查询方式（等于、不等于、大于、小于、范围）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.HTML_TYPE         IS '显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）';
COMMENT ON COLUMN GEN_TABLE_COLUMN.DICT_TYPE         IS '字典类型';
COMMENT ON COLUMN GEN_TABLE_COLUMN.SORT              IS '排序';
COMMENT ON COLUMN GEN_TABLE_COLUMN.CREATE_BY         IS '创建者';
COMMENT ON COLUMN GEN_TABLE_COLUMN.CREATE_TIME       IS '创建时间';
COMMENT ON COLUMN GEN_TABLE_COLUMN.UPDATE_BY         IS '更新者';
COMMENT ON COLUMN GEN_TABLE_COLUMN.UPDATE_TIME       IS '更新时间';


-- ----------------------------
-- 函数 ，代替MYSQL的FIND_IN_SET
-- 例如： SELECT * FROM SYS_DEPT WHERE FIND_IN_SET ('101',ANCESTORS) <> 0
-- ----------------------------
CREATE FUNCTION FIND_IN_SET ( TARGET  VARCHAR(100), STR_SET VARCHAR(2000) )
    RETURNS INTEGER
    NO EXTERNAL ACTION
    RETURN values position(','||TARGET||',',','||STR_SET||',',codeunits16);

COMMIT;










-- ----------------------------
-- 1、存储每一个已配置的 JOBDETAIL 的详细信息
-- ----------------------------
CREATE TABLE QRTZ_JOB_DETAILS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      JOB_NAME  VARCHAR(200) NOT NULL,
      JOB_GROUP VARCHAR(200) NOT NULL,
      DESCRIPTION VARCHAR(250),
      JOB_CLASS_NAME   VARCHAR(250) NOT NULL,
      IS_DURABLE VARCHAR(1) NOT NULL,
      IS_NONCONCURRENT VARCHAR(1) NOT NULL,
      IS_UPDATE_DATA VARCHAR(1) NOT NULL,
      REQUESTS_RECOVERY VARCHAR(1) NOT NULL,
      JOB_DATA BLOB,
      CONSTRAINT PK_QRTZ_JOB_D PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
);
-- ----------------------------
-- 2、 存储已配置的 TRIGGER 的信息
-- ----------------------------
CREATE TABLE QRTZ_TRIGGERS (
       SCHED_NAME VARCHAR(120) NOT NULL,
       TRIGGER_NAME VARCHAR(200) NOT NULL,
       TRIGGER_GROUP VARCHAR(200) NOT NULL,
       JOB_NAME  VARCHAR(200) NOT NULL,
       JOB_GROUP VARCHAR(200) NOT NULL,
       DESCRIPTION VARCHAR(250) ,
       NEXT_FIRE_TIME BIGINT,
       PREV_FIRE_TIME BIGINT,
       PRIORITY BIGINT ,
       TRIGGER_STATE VARCHAR(16) NOT NULL,
       TRIGGER_TYPE VARCHAR(8) NOT NULL,
       START_TIME BIGINT NOT NULL,
       END_TIME BIGINT,
       CALENDAR_NAME VARCHAR(200),
       MISFIRE_INSTR BIGINT,
       JOB_DATA BLOB,
       CONSTRAINT PK_QRTZ_T PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
       CONSTRAINT FK_QRTZ_T_TO_JOBS FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
           REFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP)
);


-- ----------------------------
-- 3、 存储简单的 TRIGGER，包括重复次数，间隔，以及已触发的次数
-- ----------------------------
CREATE TABLE QRTZ_SIMPLE_TRIGGERS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_NAME VARCHAR(200) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      REPEAT_COUNT INTEGER NOT NULL,
      REPEAT_INTERVAL BIGINT NOT NULL,
      TIMES_TRIGGERED BIGINT NOT NULL,
      CONSTRAINT PK_QRTZ_S_T PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
      CONSTRAINT FK_QRTZ_S_T_TO_T FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
          REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);


-- ----------------------------
-- 4、 存储 CRON TRIGGER，包括 CRON 表达式和时区信息
-- ----------------------------
CREATE TABLE QRTZ_CRON_TRIGGERS (
        SCHED_NAME VARCHAR(120) NOT NULL,
        TRIGGER_NAME VARCHAR(200) NOT NULL,
        TRIGGER_GROUP VARCHAR(200) NOT NULL,
        CRON_EXPRESSION VARCHAR(120) NOT NULL,
        TIME_ZONE_ID VARCHAR(80),
        CONSTRAINT PK_QRTZ_C_T PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
        CONSTRAINT FK_QRTZ_C_T_TO_T FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
            REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);
-- ----------------------------
-- 5、 TRIGGER 作为 BLOB 类型存储(用于 QUARTZ 用户用 JDBC 创建他们自己定制的 TRIGGER 类型，JOBSTORE 并不知道如何存储实例的时候)
-- ----------------------------
CREATE TABLE QRTZ_BLOB_TRIGGERS (
        SCHED_NAME VARCHAR(120) NOT NULL,
        TRIGGER_NAME VARCHAR(200) NOT NULL,
        TRIGGER_GROUP VARCHAR(200) NOT NULL,
        BLOB_DATA BLOB,
        CONSTRAINT PK_QRTZ_B_T PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
        CONSTRAINT FK_QRTZ_B_T_TO_T FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
            REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);
-- ----------------------------
-- 6、 以 BLOB 类型存储存放日历信息， QUARTZ可配置一个日历来指定一个时间范围
-- ----------------------------
CREATE TABLE QRTZ_CALENDARS (
        SCHED_NAME VARCHAR(120) NOT NULL,
        CALENDAR_NAME  VARCHAR(200) NOT NULL,
        CALENDAR BLOB NOT NULL,
        CONSTRAINT PK_QRTZ_CALENDARS PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)
);


-- ----------------------------
-- 7、 存储已暂停的 TRIGGER 组的信息
-- ----------------------------
CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_GROUP  VARCHAR(200) NOT NULL,
      CONSTRAINT PK_QRTZ_P_T_G PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)
);

-- ----------------------------
-- 8、 存储与已触发的 TRIGGER 相关的状态信息，以及相联 JOB 的执行信息
-- ----------------------------
CREATE TABLE QRTZ_FIRED_TRIGGERS (
         SCHED_NAME VARCHAR(120) NOT NULL,
         ENTRY_ID VARCHAR(95) NOT NULL,
         TRIGGER_NAME VARCHAR(200) NOT NULL,
         TRIGGER_GROUP VARCHAR(200) NOT NULL,
         INSTANCE_NAME VARCHAR(200) NOT NULL,
         FIRED_TIME BIGINT NOT NULL,
         SCHED_TIME BIGINT NOT NULL,
         PRIORITY BIGINT NOT NULL,
         STATE VARCHAR(16) NOT NULL,
         JOB_NAME VARCHAR(200) ,
         JOB_GROUP VARCHAR(200) ,
         IS_NONCONCURRENT VARCHAR(1) ,
         REQUESTS_RECOVERY VARCHAR(1) ,
         CONSTRAINT PK_QRTZ_F_T PRIMARY KEY (SCHED_NAME,ENTRY_ID)
);

-- ----------------------------
-- 9、 存储少量的有关 SCHEDULER 的状态信息，假如是用于集群中，可以看到其他的 SCHEDULER 实例
-- ----------------------------
CREATE TABLE QRTZ_SCHEDULER_STATE (
          SCHED_NAME VARCHAR(120) NOT NULL,
          INSTANCE_NAME VARCHAR(200) NOT NULL,
          LAST_CHECKIN_TIME BIGINT NOT NULL,
          CHECKIN_INTERVAL BIGINT NOT NULL,
          CONSTRAINT QRTZ_S_S_PK PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)
);

-- ----------------------------
-- 10、 存储程序的悲观锁的信息(假如使用了悲观锁)
-- ----------------------------
CREATE TABLE QRTZ_LOCKS (
        SCHED_NAME VARCHAR(120) NOT NULL,
        LOCK_NAME  VARCHAR(40) NOT NULL,
        CONSTRAINT QRTZ_LOCKS_PK PRIMARY KEY (SCHED_NAME,LOCK_NAME)
);

CREATE TABLE QRTZ_SIMPROP_TRIGGERS (
       SCHED_NAME VARCHAR(120) NOT NULL,
       TRIGGER_NAME VARCHAR(200) NOT NULL,
       TRIGGER_GROUP VARCHAR(200) NOT NULL,
       STR_PROP_1 VARCHAR(512) ,
       STR_PROP_2 VARCHAR(512) ,
       STR_PROP_3 VARCHAR(512) ,
       INT_PROP_1 BIGINT ,
       INT_PROP_2 BIGINT ,
       LONG_PROP_1 BIGINT ,
       LONG_PROP_2 BIGINT ,
       DEC_PROP_1 NUMERIC(13,4) ,
       DEC_PROP_2 NUMERIC(13,4) ,
       BOOL_PROP_1 VARCHAR(1) ,
       BOOL_PROP_2 VARCHAR(1) ,
       CONSTRAINT QRTZ_S_T_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
       CONSTRAINT QRTZ_S_T_TO_T_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
           REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);



CREATE INDEX IDX_QRTZ_J_REQ_RECOVERY ON QRTZ_JOB_DETAILS(SCHED_NAME,REQUESTS_RECOVERY);
CREATE INDEX IDX_QRTZ_J_GRP ON QRTZ_JOB_DETAILS(SCHED_NAME,JOB_GROUP);

CREATE INDEX IDX_QRTZ_T_J ON QRTZ_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);
CREATE INDEX IDX_QRTZ_T_JG ON QRTZ_TRIGGERS(SCHED_NAME,JOB_GROUP);
CREATE INDEX IDX_QRTZ_T_C ON QRTZ_TRIGGERS(SCHED_NAME,CALENDAR_NAME);
CREATE INDEX IDX_QRTZ_T_G ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
CREATE INDEX IDX_QRTZ_T_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE);
CREATE INDEX IDX_QRTZ_T_N_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE);
CREATE INDEX IDX_QRTZ_T_N_G_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE);
CREATE INDEX IDX_QRTZ_T_NEXT_FIRE_TIME ON QRTZ_TRIGGERS(SCHED_NAME,NEXT_FIRE_TIME);
CREATE INDEX IDX_QRTZ_T_NFT_ST ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME);
CREATE INDEX IDX_QRTZ_T_NFT_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME);
CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE);
CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE_GRP ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE);

CREATE INDEX IDX_QRTZ_FT_TRIG_INST_NAME ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME);
CREATE INDEX IDX_QRTZ_FT_INST_JOB_REQ_RCVRY ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY);
CREATE INDEX IDX_QRTZ_FT_J_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);
CREATE INDEX IDX_QRTZ_FT_JG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP);
CREATE INDEX IDX_QRTZ_FT_T_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);

CREATE INDEX IDX_QRTZ_FT_TG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);

COMMIT;
